#!/usr/bin/perl
#
# This test performs ioctl access on a file.
#

use Test;
BEGIN { plan tests => 2}

$basedir = $0;  $basedir =~ s|(.*)/[^/]*|$1|;

#
# Create a temporary file for testing
#
$result = system "touch $basedir/temp_file 2>&1";
$result = system "chcon -t test_ioctl_file_t $basedir/temp_file 2>&1";

#
# Attempt to perform the ioctls on the temproary file as the good domain
#
$result = system "runcon -t test_ioctl_t -- $basedir/test_ioctl $basedir/temp_file 2>&1";
ok($result, 0); 

#
# Attempt to perform the ioctls on the temproary file as the bad domain
# The test program, test_noioctl.c, determines success/failure for the
# individual calls, so we expect success always from that program.
#
$result = system "runcon -t test_noioctl_t -- $basedir/test_noioctl $basedir/temp_file 2>&1";
ok($result, 0); 

system "rm -f $basedir/temp_file 2>&1";

exit;
